import VueRouter from 'vue-router'
import Vue from 'vue'
import * as R from "ramda"
import json from "@/../data.json"
import MarkDownView from "../MarkDownView"
Vue.use(VueRouter)
const recursive =(childrenKey='children')=>callback=>list=>{
    return R.clone(list).map((item)=>{
        if(item[childrenKey]&&item[childrenKey].length) {
            item[childrenKey]=recursive(childrenKey)(callback)(item[childrenKey])
        }
       return callback(item)
    })
}
const routes= recursive('children')((i)=>{
    return {
        path:i.deep===1?'/'+encodeURIComponent(i.label):encodeURIComponent(i.label),
        name:i.id,
        meta:{
            deep:i.deep,

            ...(
                i.index?{
                    markdown:i.index.md
                }:{
                    markdown:i.md
                }
            )
        },
        component:MarkDownView,
        children:i.children
    }
})(json[0].children)
console.log(routes)
export default  new VueRouter({
    routes,
    mode:'hash'
})

